package com.yyk.yiliao.mvvm.view_model

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.orhanobut.hawk.Hawk
import com.orhanobut.logger.Logger
import com.yyk.yiliao.util.Md5Util2
import com.yyk.yykywd.network.BusinessApi
import kotlinx.coroutines.launch
import java.util.*

/**
 * 文件描述：
 * Created by guo on 2020/4/15.
 */
class MineViewModel : ViewModel() {

    var name = MutableLiveData<String>()

    init {
        getInfo()
    }

    fun getInfo() {
        viewModelScope.launch {
            val map: MutableMap<String, String> = TreeMap()
            map["id"] = Hawk.get("uid")
            map["sign"] = Md5Util2.createSign(map)
            val userInfoAsync = BusinessApi.retrofitService.getUserInfo(map)
            try {
                val userInfo = userInfoAsync.await()
                name.value = userInfo.data.money.toString()
            }catch (e:Exception) {
                Logger.e(e.toString())
            }
        }
    }
}